{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a0fa9718",
   "metadata": {},
   "source": [
    "Import required libraries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "939f4fdc",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "#Append the parent directory to the sys.path to allow imports from neuttsair package\n",
    "sys.path.append('..')\n",
    "from neuttsair.neutts import NeuTTSAir\n",
    "from IPython.display import Audio"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4e61937",
   "metadata": {},
   "source": [
    "Downloads files and loads the model into memory"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cfabf9dd",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%capture\n",
    "tts = NeuTTSAir(\n",
    "    backbone_repo=\"neuphonic/neutts-air-q8-gguf\",\n",
    "    backbone_device=\"cpu\",\n",
    "    codec_repo=\"neuphonic/neucodec\",\n",
    "    codec_device=\"cpu\"\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "75c87818",
   "metadata": {},
   "source": [
    "Pick your speaker and type up your input text - and generate!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "914e5e00",
   "metadata": {},
   "outputs": [],
   "source": [
    "speaker = \"dave\" # default speakers are 'dave' and 'jo'\n",
    "input_text = \"Hey there, I'm Andy. I'm 25 and I just moved to London. The underground is pretty confusing, but it gets me around in no time at all.\"\n",
    "\n",
    "ref_text = f\"../samples/{speaker}.txt\"\n",
    "ref_audio_path = f\"../samples/{speaker}.wav\"\n",
    "\n",
    "ref_text = open(ref_text, \"r\").read().strip()\n",
    "ref_codes = tts.encode_reference(ref_audio_path)\n",
    "wav = tts.infer(input_text, ref_codes, ref_text)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e8da4a9d",
   "metadata": {},
   "source": [
    "Listen to your generation!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "21774af1",
   "metadata": {},
   "outputs": [],
   "source": [
    "Audio(wav, rate=24000)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
